package com.ruoyi.function.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.function.domain.CarBrand;
import com.ruoyi.function.domain.CarModel;
import com.ruoyi.function.domain.CarSeries;
import com.ruoyi.function.service.ICarBrandService;
import com.ruoyi.function.utility.MiniAppTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

//获取用户车辆信息
@RestController
@RequestMapping("/api/car")
public class UserCarController {


    @Autowired
    private ICarBrandService carBrandService;

    @Autowired
    private MiniAppTokenService miniAppTokenService;

    /**
     * 获取用户车辆信息
     */


    /**
     * 获取品牌列表
     */
    @GetMapping("/brands")
    public AjaxResult getBrands() {
        List<CarBrand> brands = carBrandService.getBrandList();
        Map<String, List<CarBrand>> groupedBrands = brands.stream()
                .collect(Collectors.groupingBy(CarBrand::getInitial));
        return AjaxResult.success(groupedBrands);
    }


    /**
     * 获取汽车品牌下拉列表
     */
    @GetMapping("/listAll")
    public AjaxResult getBrandDropdown() {
        List<CarBrand> brands = carBrandService.getBrandList();
        return AjaxResult.success(brands);
    }



    /**
     * 获取车系列表
     */
    @GetMapping("/series/{brandId}")
    public AjaxResult getSeries(@PathVariable Integer brandId) {
        List<CarSeries> series = carBrandService.getSeriesList(brandId);
        return AjaxResult.success(series);
    }

    /**
     * 获取车型列表
     */
    @GetMapping("/models/{seriesId}")
    public AjaxResult getModels(@PathVariable Integer seriesId) {
        List<CarModel> models = carBrandService.getModelList(seriesId);
        return AjaxResult.success(models);
    }
} 